// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch
{
	public sealed partial class ScriptSort : ISortOptionsVariant
	{
		[JsonInclude]
		[JsonPropertyName("mode")]
		public Elastic.Clients.Elasticsearch.SortMode? Mode { get; set; }

		[JsonInclude]
		[JsonPropertyName("nested")]
		public Elastic.Clients.Elasticsearch.NestedSortValue? Nested { get; set; }

		[JsonInclude]
		[JsonPropertyName("order")]
		public Elastic.Clients.Elasticsearch.SortOrder? Order { get; set; }

		[JsonInclude]
		[JsonPropertyName("script")]
		public Elastic.Clients.Elasticsearch.Script Script { get; set; }

		[JsonInclude]
		[JsonPropertyName("type")]
		public Elastic.Clients.Elasticsearch.ScriptSortType? Type { get; set; }
	}

	public sealed partial class ScriptSortDescriptor<TDocument> : SerializableDescriptorBase<ScriptSortDescriptor<TDocument>>
	{
		internal ScriptSortDescriptor(Action<ScriptSortDescriptor<TDocument>> configure) => configure.Invoke(this);
		public ScriptSortDescriptor() : base()
		{
		}

		private Elastic.Clients.Elasticsearch.NestedSortValue? NestedValue { get; set; }

		private NestedSortValueDescriptor<TDocument> NestedDescriptor { get; set; }

		private Action<NestedSortValueDescriptor<TDocument>> NestedDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.SortMode? ModeValue { get; set; }

		private Elastic.Clients.Elasticsearch.SortOrder? OrderValue { get; set; }

		private Elastic.Clients.Elasticsearch.Script ScriptValue { get; set; }

		private Elastic.Clients.Elasticsearch.ScriptSortType? TypeValue { get; set; }

		public ScriptSortDescriptor<TDocument> Nested(Elastic.Clients.Elasticsearch.NestedSortValue? nested)
		{
			NestedDescriptor = null;
			NestedDescriptorAction = null;
			NestedValue = nested;
			return Self;
		}

		public ScriptSortDescriptor<TDocument> Nested(NestedSortValueDescriptor<TDocument> descriptor)
		{
			NestedValue = null;
			NestedDescriptorAction = null;
			NestedDescriptor = descriptor;
			return Self;
		}

		public ScriptSortDescriptor<TDocument> Nested(Action<NestedSortValueDescriptor<TDocument>> configure)
		{
			NestedValue = null;
			NestedDescriptor = null;
			NestedDescriptorAction = configure;
			return Self;
		}

		public ScriptSortDescriptor<TDocument> Mode(Elastic.Clients.Elasticsearch.SortMode? mode)
		{
			ModeValue = mode;
			return Self;
		}

		public ScriptSortDescriptor<TDocument> Order(Elastic.Clients.Elasticsearch.SortOrder? order)
		{
			OrderValue = order;
			return Self;
		}

		public ScriptSortDescriptor<TDocument> Script(Elastic.Clients.Elasticsearch.Script script)
		{
			ScriptValue = script;
			return Self;
		}

		public ScriptSortDescriptor<TDocument> Type(Elastic.Clients.Elasticsearch.ScriptSortType? type)
		{
			TypeValue = type;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (NestedDescriptor is not null)
			{
				writer.WritePropertyName("nested");
				JsonSerializer.Serialize(writer, NestedDescriptor, options);
			}
			else if (NestedDescriptorAction is not null)
			{
				writer.WritePropertyName("nested");
				JsonSerializer.Serialize(writer, new NestedSortValueDescriptor<TDocument>(NestedDescriptorAction), options);
			}
			else if (NestedValue is not null)
			{
				writer.WritePropertyName("nested");
				JsonSerializer.Serialize(writer, NestedValue, options);
			}

			if (ModeValue is not null)
			{
				writer.WritePropertyName("mode");
				JsonSerializer.Serialize(writer, ModeValue, options);
			}

			if (OrderValue is not null)
			{
				writer.WritePropertyName("order");
				JsonSerializer.Serialize(writer, OrderValue, options);
			}

			writer.WritePropertyName("script");
			JsonSerializer.Serialize(writer, ScriptValue, options);
			if (TypeValue is not null)
			{
				writer.WritePropertyName("type");
				JsonSerializer.Serialize(writer, TypeValue, options);
			}

			writer.WriteEndObject();
		}
	}

	public sealed partial class ScriptSortDescriptor : SerializableDescriptorBase<ScriptSortDescriptor>
	{
		internal ScriptSortDescriptor(Action<ScriptSortDescriptor> configure) => configure.Invoke(this);
		public ScriptSortDescriptor() : base()
		{
		}

		private Elastic.Clients.Elasticsearch.NestedSortValue? NestedValue { get; set; }

		private NestedSortValueDescriptor NestedDescriptor { get; set; }

		private Action<NestedSortValueDescriptor> NestedDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.SortMode? ModeValue { get; set; }

		private Elastic.Clients.Elasticsearch.SortOrder? OrderValue { get; set; }

		private Elastic.Clients.Elasticsearch.Script ScriptValue { get; set; }

		private Elastic.Clients.Elasticsearch.ScriptSortType? TypeValue { get; set; }

		public ScriptSortDescriptor Nested(Elastic.Clients.Elasticsearch.NestedSortValue? nested)
		{
			NestedDescriptor = null;
			NestedDescriptorAction = null;
			NestedValue = nested;
			return Self;
		}

		public ScriptSortDescriptor Nested(NestedSortValueDescriptor descriptor)
		{
			NestedValue = null;
			NestedDescriptorAction = null;
			NestedDescriptor = descriptor;
			return Self;
		}

		public ScriptSortDescriptor Nested(Action<NestedSortValueDescriptor> configure)
		{
			NestedValue = null;
			NestedDescriptor = null;
			NestedDescriptorAction = configure;
			return Self;
		}

		public ScriptSortDescriptor Mode(Elastic.Clients.Elasticsearch.SortMode? mode)
		{
			ModeValue = mode;
			return Self;
		}

		public ScriptSortDescriptor Order(Elastic.Clients.Elasticsearch.SortOrder? order)
		{
			OrderValue = order;
			return Self;
		}

		public ScriptSortDescriptor Script(Elastic.Clients.Elasticsearch.Script script)
		{
			ScriptValue = script;
			return Self;
		}

		public ScriptSortDescriptor Type(Elastic.Clients.Elasticsearch.ScriptSortType? type)
		{
			TypeValue = type;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (NestedDescriptor is not null)
			{
				writer.WritePropertyName("nested");
				JsonSerializer.Serialize(writer, NestedDescriptor, options);
			}
			else if (NestedDescriptorAction is not null)
			{
				writer.WritePropertyName("nested");
				JsonSerializer.Serialize(writer, new NestedSortValueDescriptor(NestedDescriptorAction), options);
			}
			else if (NestedValue is not null)
			{
				writer.WritePropertyName("nested");
				JsonSerializer.Serialize(writer, NestedValue, options);
			}

			if (ModeValue is not null)
			{
				writer.WritePropertyName("mode");
				JsonSerializer.Serialize(writer, ModeValue, options);
			}

			if (OrderValue is not null)
			{
				writer.WritePropertyName("order");
				JsonSerializer.Serialize(writer, OrderValue, options);
			}

			writer.WritePropertyName("script");
			JsonSerializer.Serialize(writer, ScriptValue, options);
			if (TypeValue is not null)
			{
				writer.WritePropertyName("type");
				JsonSerializer.Serialize(writer, TypeValue, options);
			}

			writer.WriteEndObject();
		}
	}
}